package com.ruoyi.project.authless;

import com.alibaba.fastjson.JSON;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.model.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.business.controlcenter.iot.manager.IotManager;
import com.ruoyi.project.business.controlcenter.request.DeviceAutoPingRequest;
import com.ruoyi.project.business.controlcenter.request.IotRequest;
import com.ruoyi.project.business.gpiobiz.request.ListControlGpioBizRequest;
import com.ruoyi.project.business.gpiobiz.response.ControlGpioBizResponse;
import com.ruoyi.project.business.gpiobiz.service.IControlGpioBizService;
import com.ruoyi.project.business.nativedevice.service.INativeDeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备联网后自动上报 mac
 * 
 */
@Slf4j
@RestController
@RequestMapping("/authless")
public class AuthlessController extends BaseController {
    @Autowired
    private INativeDeviceService nativeDeviceService;

    @PostMapping("/device-online")
    public AjaxResult deviceOnline(@RequestBody DeviceAutoPingRequest req) {
        log.info("device-auto-ping... {}", JSON.toJSONString(req));
        nativeDeviceService.saveOrUpdateDevice(req.getIp(), req.getMac(), req.getDevicecode());
        return AjaxResult.success("ok");
    }

    @PostMapping("/device-offline")
    public AjaxResult deviceOffline(@RequestBody DeviceAutoPingRequest req) {
        log.info("device-auto-ping... {}", JSON.toJSONString(req));
        nativeDeviceService.saveOrUpdateDevice(req.getIp(), req.getMac(), req.getDevicecode());
        return AjaxResult.success("ok");
    }
    
}
